package com.pactera.asmp.server.common.threadpool.workqueue;


import com.pactera.asmp.server.common.logprint.utils.LogUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * <p>Class: com.lzq.plugin.threadpool.workqueue.WorkThreadRejectedExecutionHandler</p>
 * <p>Description: </p>
 * <pre>
 *
 * </pre>
 *
 * @author lv zhiqiang
 * @date 2019/7/17/12:07
 */
public class WorkThreadRejectedExecutionHandler implements RejectedExecutionHandler {
    private static final Logger logger = LoggerFactory.getLogger(WorkThreadRejectedExecutionHandler.class);
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        logger.error("rejectedExecution:  " + r.toString() + " rejected from " + executor.toString());
        if (!executor.isShutdown()) {
            executor.getQueue().poll();
            executor.execute(r);
        }
    }
}
